#include <thread>
#include "Core/Notification/Notification.h"
#include "Core/Log/LogManager.h"
#include "Core/Profile/CodeProfile.h"
#include "NotificationTest.h"

const char * NotificationTest::GetName() const
{
	return "[CORE] Notification Test";
}

Core::error NotificationTest::Create()
{
	if(Failed(UnitTest::Create()))
		return Core::errFailed;

	m_pHandler1 = new Handler1;
	m_pHandler2 = new Handler2;
	m_pSender = new Sender;

	return Core::errOK;
}

Core::error NotificationTest::Destroy()
{
	if(Failed(UnitTest::Destroy()))
		return Core::errFailed;

	delete m_pHandler1;
	delete m_pHandler2;
	delete m_pSender;

	return Core::errOK;
}

Core::error NotificationTest::Execute()
{
	PROFILE(GetName());

	m_pHandler1->toto = 45;
	m_pHandler2->toto = 45;
	m_pSender->Process();

	int tries = 0;
	while (m_pHandler1->toto != 10 || m_pHandler2->toto != 20)
	{
		std::chrono::milliseconds dura(100);
		std::this_thread::sleep_for(dura);
		tries++;
		if (tries>10)
			return Core::errFailed;
	}

	return Core::errOK;
}
